<template>
  <div >
    <div class="index">
      <div>
        <h3 style="margin-left: 190px">热搜总数</h3>
        <div class="piechart" id="piechart" style="width: 450px;height: 300px;margin-left: 0px"></div>
      </div>
      <div class="rate">
        <h3 style="margin-left: 20px;">评价平均分</h3>
        <el-rate
          v-model="value"
          disabled
          show-score
          text-color="#ff9900"
          score-template="{value}"  style="margin-top: 120px">
        </el-rate>
      </div>
      <div>
        <h3 style="margin-left: 250px">今日新增热榜数</h3>
        <div class="addpie" id="addpie" style="width: 550px;height: 300px;margin-left: 80px"></div>
      </div>
    </div>
    <el-descriptions  direction="vertical" :column="4" border style="width: 1300px;margin-left: auto;margin-right: auto;margin-top: 30px">
      <el-descriptions-item label="用户总数" :span="1">{{ usercount }}</el-descriptions-item>
      <el-descriptions-item label="今日新增用户数" :span="1">{{ newadduser }}</el-descriptions-item>
      <el-descriptions-item label="评论总数" :span="1">{{ commentcount }}</el-descriptions-item>
      <el-descriptions-item label="今日新增评论数" :span="1">{{ newaddcomment }}</el-descriptions-item>
      <el-descriptions-item label="百度热榜总数" :span="1">{{ bdhotcount }}</el-descriptions-item>
      <el-descriptions-item label="今日热榜总数" :span="1">{{ jrhotcount }}</el-descriptions-item>
      <el-descriptions-item label="腾讯热榜总数" :span="1">{{ txhotcount }}</el-descriptions-item>
      <el-descriptions-item label="微博热榜总数" :span="1">{{ wbhotcount }}</el-descriptions-item>
    </el-descriptions>
  </div>
</template>

<script>
import { getCount,getYesterNewAdd,getComment,getUser,getAvgRate } from "@/api/index";
import {getNewAddComment, getNewAddUser} from "../api";
export default {
  name: "Index",
  data() {
    return {
      // 版本号
      version: "3.8.1",
      usercount:"",
      commentcount:"",
      bdhotcount:null,
      jrhotcount:null,
      txhotcount:null,
      wbhotcount:null,
      newadduser:0,
      newaddcomment:0,
      value: 5,
    };
  },
  methods: {
    getUser(){
      getUser().then(response => {
        this.usercount = response.data;
      });
    },
    getNewAddComment(){
      getNewAddComment().then(response => {
        this.newaddcomment = response.data;
      });
    },
    getNewAddUser(){
      getNewAddUser().then(response => {
        this.newadduser = response.data;
      });
    },
    getComment(){
      getComment().then(response => {
        this.commentcount = response.data;
      });
    },
    getCount(){
      getCount().then(response => {
        this.wbhotcount = response.data[0].value;
        this.txhotcount = response.data[1].value;
        this.jrhotcount = response.data[2].value;
        this.bdhotcount = response.data[3].value;
        const myChart = this.$echarts.init(document.getElementById('piechart'))
        // 绘制图表
        myChart.setOption( {
          tooltip: {
            trigger: 'item'
          },
          legend: {
            top: '5%',
            left: 'center'
          },
          series: [
            {
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              itemStyle: {
                borderRadius: 10,
                borderColor: '#fff',
                borderWidth: 2
              },
              label: {
                show: false,
                position: 'center'
              },
              emphasis: {
                label: {
                  show: true,
                  fontSize: '40',
                  fontWeight: 'bold'
                }
              },
              labelLine: {
                show: false
              },
              data: response.data
            }
          ]
        })
      });
    },
    getAdd(){
      getYesterNewAdd().then(response => {
        const myChart = this.$echarts.init(document.getElementById('addpie'))
        // 绘制图表
        myChart.setOption( {
          tooltip: {//提示框组件
            trigger: 'item', //item数据项图形触发，主要在散点图，饼图等无类目轴的图表中使用。
          },

          xAxis: {},
          yAxis: {
            type:"category",
            data: ["微博热搜","腾讯热榜","今日热榜","百度热搜"]
          },
          series: [{
            name: '新增数',
            type: 'bar',
            data: response.data
          }]
        })
      });
    },
    getAvgRate(){
      getAvgRate().then(response => {
        this.value=response.data
      });
    }
  },
  created() {

  },
  mounted() {
    this.getCount()
    this.getAdd()
    this.getUser()
    this.getComment()
    this.getAvgRate()
    this.getNewAddComment()
    this.getNewAddUser()
  }
};
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }


}
.index{
  display: flex;
  margin-top: 50px;
  width: 1300px;
  margin-left: auto;margin-right: auto;
}
.rate{
  margin-left: 50px;
}
</style>

